package org.edu.modules.classChoise.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.edu.modules.classChoise.entity.VeJwSxjxsec;
import org.edu.modules.classChoise.mapper.VeJwSxjxsecMapper;
import org.edu.modules.classChoise.service.IVeJwSxjxsecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 选课时间
 * @Author:
 * @Date:   2021-05-14
 * @Version: V1.0
 */
@Service
public class VeJwSxjxsecServiceImpl extends ServiceImpl<VeJwSxjxsecMapper, VeJwSxjxsec> implements IVeJwSxjxsecService {

    @Autowired
    private VeJwSxjxsecMapper veJwSxjxsecMapper;


    @Override
    @Transactional
    public boolean setScheduleForSec(List<VeJwSxjxsec> veJwSxjxsec,int sxjxId) {
        try {
            veJwSxjxsecMapper.deleteAll(sxjxId);
            if ((veJwSxjxsec!=null)&&(veJwSxjxsec.size()>0)){
            for (int i=0;i<veJwSxjxsec.size();i++) {
                //veJwBpksj.setId(null);
                VeJwSxjxsec veJwSxjxsecinfo=veJwSxjxsec.get(i);
                veJwSxjxsecinfo.setSxjxid(sxjxId);
                veJwSxjxsecMapper.insert(veJwSxjxsecinfo);
            }}
            return true;
        }
        catch (Exception ex){
            return false;
        }

    }



    @Override
    @Transactional
    public  List<Map<String, Object>>  selectSxjxId(int sxjxId) {
        try {
            List<Map<String, Object>> list= veJwSxjxsecMapper.selectSxjxId(sxjxId);
            return list;
        }
        catch (Exception ex){
            return null;
        }
    }

    @Override
    @Transactional
    public boolean delScheduleForSec(List<VeJwSxjxsec> veJwSxjxsecs,String Secid) {
        try {
            //veJwSxjxsecMapper.deleteAll(Secid);
            for (VeJwSxjxsec veJwSxjxsec : veJwSxjxsecs) {
                //veJwBpksj.setId(null);
             //   veJwSxjxsecMapper.delete(veJwSxjxsec.getSection(),veJwSxjxsec.getSxjxId());
            }
            return true;
        }
        catch (Exception ex){
            return false;
        }
    }
}
